package icasue.reflect.handles.string;

import icasue.reflect.exceptions.HandleException;
import icasue.reflect.handles.HandleSupplier;
import icasue.reflect.handles.OFAble;
import icasue.reflect.handles.exception.ExceptionOF;
import icasue.reflect.handles.predicate.SureOF;

import java.util.function.Function;

/**
 * @Author: Qiao Hang
 * @CreateDate: 2020/12/2 上午11:48
 * @UpdateDate:
 * @Description:
 */
public class StringOF implements OFAble {

    /**
     *  valueOf_  (obj)
     *  join_List_  (delimiter,collection)
     *
     *  All method check pass.
     */

    public static Function<Object,Object> valueOf_ = (obj) -> {
        try {
            return StringO.valueOf.invoke(obj);
        } catch (HandleException deepError){
            throw deepError;
        } catch (Throwable throwable) {
            throw ExceptionOF.handleExcInvocation_.apply("StringOF.valueOf_ : occur an error : " , throwable.getMessage());
        }
    };

    public static HandleSupplier.FunctionAry<Object> join_List_ = (params) -> {
        try {
            if(params.length != 2)
                throw ExceptionOF.handleExcInvocation_.apply("StringOF.join_List_ : required 2 params,first param must be java.lang.String, " +
                        "second param must assignable from java.lang.Iterable. ");
            SureOF.isStr_.accept(params[0]);
            SureOF.isColl_.accept(params[1]);
            return StringO.join_List.invoke(params[0],params[1]);
        } catch (HandleException deepError){
            throw deepError;
        } catch (Throwable throwable) {
            throw ExceptionOF.handleExcInvocation_.apply("StringOF.join_List_ : occur an error : " , throwable.getMessage());
        }
    };
}
